package rs.etf.kdp.client;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;

/**
 * @author Djordje Vukovic
 * @version 1.0
 * @created 16-May-2011 4:59:09 PM
 */
public class Connections implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 5687888184217765026L;
	private ArrayList<String[]> listOfConnections;

	public ArrayList<String[]> getListOfConnections() {
		return listOfConnections;
	}

	public Connections(){
		listOfConnections = new ArrayList<String[]>();
	}
	
	public void loadFromFile(File connectionsFile) throws IOException
	{
		FileReader reader = new FileReader(connectionsFile);
		BufferedReader breader = new BufferedReader(reader);
		
		String line = breader.readLine();
		
		while ((line = breader.readLine())!= null)
		{
			String[] tok = line.split(" ");
			listOfConnections.add(tok);
		}
	}
	
	public String[][] getConnectionMatrix()
	{
		int inList = listOfConnections.size();
		String[][] matrix = new String[inList][4];
		
		
		for(int i=0; i<inList; i++)
		{
			String[] current = listOfConnections.get(i);
			for(int j =0; j< 4; j++)
			{
				matrix[i][j] = current[j];
			}
		}

		return matrix;
	}

//	public void print()
//	{
//		String[][] m = getConnectionMatrix();
//		
//		
//		for(int i=0; i<m.length; i++)
//		{
//			for(int j=0; j<m[i].length; j++)
//			{
//				System.out.print(m[i][j] + " ");
//			}
//			System.out.println();
//		}
//	}
//	
//	public static void main(String[] str)
//	{
//		Connections c = new Connections();
//		File f = new File("res/testconnections.txt");
//		try {
//			c.loadFromFile(f);
//			c.print();
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//	}

}